﻿/*----------------------------------------------------------------------------------------
*
*  Copyright 2019, Gao Hai Hui, <fromzeropoint@126.com>.  All rights reserved.
*  https://gitee.com/helloworldghh/xoskit.git
*  Use of this source code is governed by a MIT license
*  that can be found in the License file.
*
----------------------------------------------------------------------------------------*/
#include "../import/head.h"
#include "../global/head.h"
#include "log_msg.h"

///////////////////////////////////////////////////////////////////////////////////////////////////

namespace xos_log
{
    //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    // 

    static log_msg::POOL * pool_ptr = 0;

    ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

    log_msg::log_msg()
    {
        m_nSrcCodeLine = 0;
        m_nLevel = 0;
        m_nMilliSecond = 0;
        m_nYear = 0;
        m_nMonth = 0;
        m_nDay = 0;
        m_nHour = 0;
        m_nMinute = 0;
        m_nSecond = 0;
    }

    log_msg::~log_msg()
    {
        term();
    }

    ///////////////////////////////////////////////////////////////////////////////////////////////////
    // 帮助函数

    int log_msg::get_addr( POOL *** pppPool, LIST *** pppList )
    {
        int ret = 0;
        if( pppPool )
        {
            *pppPool = &pool_ptr;
        }
        if( pppList )
        {
            *pppList = 0;
        }
        return ret;
    }

    int log_msg::init()
    {
        int nRet = 0;
        return nRet;
    }

    int log_msg::term()
    {
        int nRet = 0;

        m_nSrcCodeLine = 0;
        m_nLevel = 0;
        m_nMilliSecond = 0;
        m_nYear = 0;
        m_nMonth = 0;
        m_nDay = 0;
        m_nHour = 0;
        m_nMinute = 0;
        m_nSecond = 0;

        return nRet;
    }

    int log_msg::release()
    {
        int nRet = 0;
        term();
		put_back_to_pool( this, true );
        return nRet;
    }

    ///////////////////////////////////////////////////////////////////////////////////////////////////
    // LogMsg method

    // 得到合成后的日志全内容
    const char * log_msg::get_log_content( char * lpszLogContent, int nCharNum, int * lpnRetCharNum )
    {
        int nLen = 0;

        if( ( lpszLogContent || lpnRetCharNum ) )
        {
            nLen = ( int )m_log.length();
        }

        if( lpszLogContent && ( nCharNum > nLen - 1 ) )
        {
            g_pSysData->m_pContainer->crt()->strcpy( lpszLogContent, nCharNum, m_log.c_str() );
        }

        if( lpnRetCharNum )
        {
            *lpnRetCharNum = nLen;
        }

        return m_log.c_str();
    }

    // 得到日志时间
    int log_msg::get_log_time( int * lpnYear, 
            int * lpnMonth, 
            int * lpnDay,
            int * lpnHour, 
            int * lpnMinute, 
            int * lpnSeconde, 
            int * lpnMilliSecond )
    {
        int nRet = 0;

        if( lpnYear )
        {
            *lpnYear = m_nYear;
        }

        if( lpnMonth )
        {
            *lpnMonth = m_nMonth;
        }

        if( lpnDay )
        {
            *lpnDay = m_nDay;
        }

        if( lpnHour )
        {
            *lpnHour = m_nHour;
        }

        if( lpnMinute )
        {
            *lpnMinute = m_nMinute;
        }

        if( lpnSeconde )
        {
            *lpnSeconde = m_nSecond;
        }

        if( lpnMilliSecond )
        {
            *lpnMilliSecond = m_nMilliSecond;
        }

        return nRet;
    }

} // xos_log
